import {list} from '../../../../api/navigation'
import { getCurrent } from "../../../../api/company"
const util = require('../../../../utils/util.js')
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info:{
      type:Object
    }
},
  lifetimes:{
    attached(){
      this.data.info = {
      createDate: 1672996757000,
      dataType: 9,
      enterpriseId: 16,
      id: 6273,
      linkType: true,
      modifyDate: 1672996757000,
      name: "category_five",
      rows: 5,
      rowsType: true,
      subTitle: "",
      subTitleType: true,
      tagids: "20",
      tagidsType: false,
      title: "五图导航",
      titleType: false
    }
      this.data.pageSize = this.data.info.rows
      if (this.data.pageSize > 5){
        this.data.pageSize = 5
      }
      if (this.data.info.tagids != null) {
        this.data.tagIds = this.data.info.tagids.split(',')
        for (var i = 0; i < this.data.tagIds.length; i++) {
          this.data.tagIds[i] = parseInt(this.data.tagIds[i])
        }
      }
        this.setData({
          tagIds:this.data.tagIds
        })
      // this.loadNavigation()
    }
  },

  data: {
    company:{},
    tagIds:[],
    navigations:[
      {
        name:'一键购油',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/yijiangouyou.png'
      },
      {
        name:'商品列表',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/shangping.png'
      },
      {
        name:'定金购油',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/jiehuomaiyou.png'
      },
      {
        name:'在线提油',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/zaixiantiyou.png'
      },
      {
        name:'企业认证',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/qiyerenzheng.png'
      },
      // {
      //   name:'拼拼油',
      //   logo:'http://oss.suoyoubao.com.cn/syb/szkj/app/img//index/pinpinyou.png'
      // },
      {
        name:'新增预售',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/xinzengyushou.png'
      },
      {
        name:'客户求购',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/kehuqiugou.png'
      },
      {
        name:'申请开票',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/kaipiaoguanli.png'
      },
      {
        name:'关于我们',
        logo:'https://rzico.oss-cn-shenzhen.aliyuncs.com/suo-you-bao/guanyuwomen.png'
      }
    ],
    pageSize:5,
  },

  methods: {
    getCurrent(){
      getCurrent().then(res =>{
          this.data.company = res.data.company
          this.setData({
              company: this.data.company
          })
      })
  },
    loadNavigation(){
      list({
        mchId:app.globalData.mchId,
        pageSize:this.data.pageSize,
        tagIds:this.data.tagIds,
        pageStart:(this.data.pageSize -1)*this.data.pageSize
      }).then(res=>{
        res.data.data.forEach(item =>{
          res.data.data.push(item)
        })
            this.data.navigations=res.data.data
            this.data.navigations.forEach(function (item) {
              item.logo = util.thumbnail(item.logo,96,96)
            })
            this.setData({
              navigations: this.data.navigations
            })
      })
    },
    toRecommend(e){
      if( e.currentTarget.dataset.id.name == '一键购油'){
        if(app.globalData.token == null){
            wx.navigateTo({
              url: '/pages/safety/login',
            })
         }else if(app.globalData.token != null){
          if(this.data.company.status == 1){
            wx.showToast({
              title: '请先认证',
              icon:'none'
            })
            return false
          }
            wx.navigateTo({
              url: '/pages/pagesGoods/goods/quick',
            })        
        }
      }
      if( e.currentTarget.dataset.id.name == '企业认证'){

          if(app.globalData.token == null){
            wx.navigateTo({
              url: '/pages/safety/login',
            })
           }else if(app.globalData.token != null){
            wx.navigateTo({
              url: '/pages/pagesUser/companyInfo/attestation',
            })    
          }
      }
      if( e.currentTarget.dataset.id.name == '拼拼油') {
        return  false
        wx.navigateTo({
          url: '/pages/goods/pinpinyou',
        })
      }
      if( e.currentTarget.dataset.id.name == '商品列表') {
        // wx.navigateTo({
        //   url: '/pages/pagesGoods/goods/search',
        // })
        if(app.globalData.token == null){
          wx.navigateTo({
            url: '/pages/safety/login',
          })
         }else if(app.globalData.token != null){
          wx.navigateTo({
            url: '/pages/product/product',
          })
      }
      }
      if( e.currentTarget.dataset.id.name == '关于我们') {
        wx.navigateTo({
          url: '/pages/pagesCommon/aboutUs/aboutUs',
        })
      }
    },
  }
})
